package ecmnext.utils.gui;

/***************************************************************/
/*                     SOFTWARE SECTION                        */
/***************************************************************/
/*
 * <p>Name: ECMNext</p>
 * <p>Description: Simulation of the platform of trading Software</p>
 * <p>Licence: General Public License</p>
 * <p>Organisation: EC Marseille</p>
 * <p>Persons involved in the project : groupe Plateforme de Trading</p>
 * <p>Current version: 1.0</p>
 */

/***************************************************************/
/*                      IMPORT SECTION                         */
/***************************************************************/

import javax.swing.table.*;
import java.awt.*;
import javax.swing.*;

/***************************************************************/
/*           JButtonRenderer INTERFACE SECTION                 */
/***************************************************************/
/**
 * <p>Title: JButtonRenderer</p>
 * <p>Description:</p>
 * @author Xuewen YANG ET Antoine COUDERC
 * @version 0.2
 */


public class JButtonRenderer extends JButton implements TableCellRenderer{
  public JButtonRenderer() {
      setOpaque(true); //MUST do this for background to show up.
    }

    public Component getTableCellRendererComponent(
                            JTable table, Object jButton,
                            boolean isSelected, boolean hasFocus,
                            int row, int column) {
      Color newColor;
      String newtext;
      Font newFont;
      if ((jButton != null) && (jButton instanceof JButton)) {
        newColor = ( (JButton) jButton).getBackground();
        newtext = ( (JButton) jButton).getText();
        newFont = ((JButton)jButton).getFont();
        setBackground(newColor);
        this.setFont(newFont);
        this.setBorderPainted(false);
      }
      else {
        newtext = "";
      }

      setText(newtext);
      this.setHorizontalAlignment(this.CENTER);
      this.setVerticalAlignment(this.CENTER);
      return this;
    }
  }
